package com.ssgz.sso.login;

import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.ReplicatedMap;
import com.ssgz.sso.config.ClusterConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
public class LoginController {
    /**
     * 登录页面
     * @return
     */
    @RequestMapping({"/",""})
    public String loginPage(HttpServletRequest request){
        request.getSession();
        return "login/index";
    }


    @Autowired
    HazelcastInstance hazelcastInstance;
    @RequestMapping("test")
    @ResponseBody
    public String routerTest(){
        ReplicatedMap<String, String> replicatedMap = hazelcastInstance.getReplicatedMap(ClusterConfig.CLUSTER_SERVER_GROUP_ROUTE);
        replicatedMap.put("usercode:aaaa","a");
        replicatedMap.put("usercode:bbbb","b");
        return "success";
    }

    @RequestMapping("session")
    @ResponseBody
    public String routerTest2(HttpSession httpSession){
        httpSession.setAttribute("usercode","aaaa");
        return "success";
    }
}
